


$(function(){$('#mytable').datagrid({
	url:'../TicketServlet?action=query',
	pagination:true,
	width:900,
	height:600,
	
	title:'请输入查询条件',
	toolbar:'#searchtool',
	loadMsg:'数据加载中，请稍后...',
	pageSize:5,
	singleSelect:"true",
	pageList:[5,10,15,20],
	columns:[[
		{
			title:'编号',
			field:'id',
			width:'100'},
			{
				title:'出发地',
				field:'splace',
				width:'100'},
			{
				title:'目的地',
				field:'eplace',
				width:'100'},
			{
				title:'车次',
				field:'train',
				width:'100'},
			{
				title:'时间',
				field:'times',
				width:'150',
				formatter: formatDatebox},
			{
				title:'价格',
				field:'price',
				width:'100'},
			{
				title:'余票',
				field:'nums',
				width:'100'}
							
	]]
	
}),
$("#mytable").datagrid("getPager").pagination({
	  beforePageText: '第',//页数文本框前显示的汉字 
    afterPageText: '页    共 {pages} 页', 
    displayMsg: '当前显示 {from} - {to} 条记录   共 {total} 条记录'
}),

$("#search").on("click" , function(){
	var splace=$('#splace').val();
	var eplace=$('#eplace').val();
	var times=$('#times').val();
	$.ajax({  
		url:'../TicketServlet?action=query', 
        type: 'GET',  
        contentType:"application/json" ,
        cache: false,
        data:{"splace":splace,"eplace":eplace,"times":times,"page":page,"rows":rows},
        success: function(pager){
			$("#mytable").datagrid();
        }
    });
})

})
function doSearch(){  
    $('#mytable').datagrid('load',{
    	splace: $('#splace').val(),
    	eplace:$('#eplace').val(),
    	times:$('#times').val(),
    	train:$('#train').val()
    })
   
}

function doReserve(){
	 var row = $('#mytable').datagrid('getSelected');
	 if(row){
//		 $.post('../TicketServlet?action=reserve', {
//				tid : row.id})
		 var tid=row.id;
		 window.location.href="../TicketServlet?action=reserve&tid="+tid;
		// window.open('http://localhost:8080/GoodProject/TicketServlet?action=reserve&tid='+tid);
		//var tid=row.id;
	 }else{
		 alert("请选择正确的车次!");
	 }
}
Date.prototype.format = function (format) {    
    var o = {    
        "M+": this.getMonth() + 1, // month    
        "d+": this.getDate(), // day    
        "h+": this.getHours(), // hour    
        "m+": this.getMinutes(), // minute    
        "s+": this.getSeconds(), // second    
        "q+": Math.floor((this.getMonth() + 3) / 3), // quarter    
        "S": this.getMilliseconds()    
        // millisecond    
    }    
    if (/(y+)/.test(format))    
        format = format.replace(RegExp.$1, (this.getFullYear() + "")    
            .substr(4 - RegExp.$1.length));    
    for (var k in o)    
        if (new RegExp("(" + k + ")").test(format))    
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));    
    return format;    
}    
function formatDatebox(value) {    
    if (value == null || value == '') {    
        return '';    
    }    
    var dt;    
    if (value instanceof Date) {    
        dt = value;    
    } else {    
        dt = new Date(value);    
    }    
    
    return dt.format("yyyy-MM-dd hh:mm:ss");     
}


 











